local desc_norkj_mode = [[
  # 普通军八抗金简介
  ___

  军八4个玩家（身份固定为主忠，玩家不足人机补位）对抗4个人机（身份固定为反贼）。当所有反贼死亡后，它们将换将复活并强化然后战斗下一轮挑战组人机直到满足胜利或失败条件。

  胜利条件：反贼全部阵亡且达到设定的挑战组。

  失败条件：主忠全部阵亡。

  先登制敌（按照当前挑战轮数是否可触发）：每轮开始，每个玩家从以下选项中随机取3个让玩家可选1个执行其效果。
    兵多：锁定技，获得此技能时你摸3张牌，回合内手牌上限-1，每轮结束失去此技能。
    将广：你可以从4个和你同势力的武将技能里选2个技能获得，当因此获得的技能生效后失去该技能。（如果有未触发技能则每轮结束失去这些技能）。
    狂妄：锁定技，你获得此技能后，体力和体力上限+2。每个回合开始你进行一次闪电判定。每轮结束你失去此技能且体力上限-1。
    流星：其他随机x名与你不同阵营的角色受到1点火属性伤害。（x为与你不同阵营角色总数的一半）。
    强将：你可以从3个和你同势力的武将技能里选1个技能获得，每轮结束失去此技能。
    换位：你选择一名其他角色与其互换位置。
    戎装：你从牌堆中随机检索两张不同类别的装备牌置入你的装备区。
    落日：与你不同阵营的x名角色流失1点体力。（x为与你不同阵营角色总数的一半）。
    杀意：锁定技，你的出牌阶段额外使用2张杀。回合结束失去此技能。
    陨石：与你不同阵营的x名角色丢弃2张牌。（x为与你不同阵营角色总数的一半）。
    点兵：你从基本，锦囊，装备牌类型中选择一项。再从此类型的所有牌名里选一张卡获得。
    终战：你的回合开始，若你发动此技能你的体力上限变为1，然后你摸损失的体力上限的牌数且本回合内你使用牌没有距离与次数限制，回合结束你死亡。若不发动失去此技能。

  战功设定：游戏开始，所有主忠角色获得【战功】技能：锁定技，当你获得某些标记能够强化自身。
    强化标记有：摸牌阶段额外摸牌+x，手牌上限+x，每轮开始获得护盾+x，出牌阶段额外使用杀次数+x，额外杀目标数+x。（x为获得的对应标记数）

  斩将设定：每次出现反贼武将将有概率获得【斩将】技能：锁定技，当你死亡时，杀死你的角色（要有【战功】技能）从3个随机的强化标记选项中选1个获得。

  复活：当刷新下一挑战轮数。所有死亡的主忠角色将满血复活，未死亡将获得额外摸牌。

]]
-- local XlkjObj = require "packages/xlkj/XlkjObj"
local U = require "packages/utility/utility"
local SelGenMuty = require "packages/lang/SelGenMuty"
local KJobj = require "packages/lang/KJobj"

--开启测试
local IStest
--开启测试AI武将
local IStestAI = false

--主忠通过斩将升级的标记
local UpMarks = {"@drcdnum","@handsmax","@slashadd","@slashtar","@shieldadd"}
--斩将奖励池
local wangyuRwds = {"unknow_reward","addmaxhp_1","draw_4","@drcdnum","@handsmax","@shieldadd","@slashadd","@slashtar","jianghun"}--"rechp_2",
-- local wangyuRwds = {"jianghun","jianghun","jianghun","jianghun","jianghun",}--"rechp_2",
--下一轮战斗准备数据
local nextBattleData = {
  {
    xiandengnum = 1,
    getsameskills = {lord = {"kj_gongjue"},loyalist = {"kj_gongjue"}},
    deadthsing = {rebel = {0,0,1,0}},
    -- deadthsing = {rebel = {1,1,1,1}},
  },
  {
    xiandengnum = 1,
    getcardnum = {rebel=5,lord = 2,loyalist=2},
    getmaxhp = {rebel=1},
    deadthsing = {rebel = {0,0,1,1}},
  },
  {
    xiandengnum = 1,
    getcardnum = {lord = 2,loyalist=2,rebel=5},
    getmaxhp = {lord = 1,loyalist=1,rebel=1},
    getsameskills = {rebel = {"ex__yingzi","rongzhuangSkill"}},
    deadthsing = {rebel = {0,1,1,1}},
    rongzhuangnum = {rebel = 1}
  },
  {
    xiandengnum = 2,
    getcardnum = {lord = 3,loyalist=3,rebel=6},
    getmaxhp = {rebel=2},
    getsameskills = {rebel = {"m_ex__dangxian","rongzhuangSkill"}},
    deadthsing = {rebel = {1,1,1,1}},
    rongzhuangnum = {rebel = 2}
  },
  -- {
  --   xiandengnum = 2,
  --   getcardnum = {lord = 3,loyalist=3,rebel=6},
  --   getmaxhp = {rebel=2},
  --   getsameskills = {rebel = {"yingjian","chouce","rongzhuangSkill"}},
  --   deadthsing = {rebel = {1,1,1,1}},
  --   rongzhuangnum = {rebel = 2}
  -- },
}
--战斗轮数
local battleTurn = #nextBattleData
--当前轮数
local curTurn = 1
--将广技能池
local jiangguangSkills = {
  wei={"ex__jianxiong","ex__fankui","ex__ganglie","ex__qingjian","jiushi","ex__tuxi","ex__luoyi","ex__luoshen","xunxun","chengxiang","jianmie",
  "ol_ex__miji","ol_ex__shebian","ol_ex__jushou","ol_ex__jieming","quhu","ol_ex__duanliang","bolong","weikui","lizhan","ol__jingce","benyu",
  "benyu","yawang","gushe","chouce","weijing","ol__wanwei","jixian","saodi","zengou","huanfu","gongjie","tousui","ex__yiji","os__kaiji"},

  shu={"ex__rende","ex__yijue","os__zhibian","ex__guanxing","yajiao","ex__tieji","jianyan","jijie","m_ex__fangquan","m_ex__tiaoxin","ol_ex__liegong","mini__kuanggu",
  "ol_ex__huoji","ol_ex__lianhuan","ol_ex__xuanhuo","zhanding","zhuri","ol__xuehen","ol__sanyao","fengpo","ziyuan","bingzheng","shuimeng","jianji","dianjun",
  "hongji","os_ex__lieren","os__jimeng","os__shuaiyan","os__jieyu"},

  wu={"ex__zhiheng","os__fenghan","fenwei","gongxin","keji","kurou","ex__yingzi","ex__fanjian","ex__guose","ex__qianxun","ex__jieyin","ol_ex__zhiyan","zhijian","ol_ex__guzheng",
  "ol_ex__ganlu","ol_ex__zhiyan","bizheng","duwu","jinzhi","yingjian","anjian","os_ex__gongqi","os__fenwu","os__shangyi","anxu","ty_ex__xingxue"},

  qun={"qingnang","os_xing__zhilue","liyu","ol_ex__jianchu","ex__biyue","lijian","ty_ex__qiaomeng","ty__kuangfu","ol_ex__beige","m_ex__luanji","ol_ex__mieji","ol_ex__qieting",
  "zhidao","lianzhu","tunjiang","liejie","jianman","kenshang","langdao","shandao","yichengl","hunjiang","guixin","os__dingfa","os__moukui","os__yimou","os__juchen","shelie",
  "os__daoji","os__daigui","os__weipo","os__jiange","os__xuechang"},
}
--强将技能池
local qiangjiangSkills = {
  wei={"qingguo","ty__wangxi","ol_ex__renxin","ol_ex__chengxiang","luoying","ol_ex__jiangchi","ol_ex__zhenlie","ol_ex__shensu","ol_ex__jiewei","ol_ex__qiangxi",
  "xieshu","ol__qingxian","ol__caishi","tuifeng","qingzhong","ol__yuejian","zhangjiq","kanpod","gengzhan","qingyix","xiangxu","os__shepan","os__zhongzuo","os__zhanyi",
  "os__yuanhu"},

  shu={"ol_ex__kanpo","os__yuyan","ol_ex__changbiao","ol_ex__enyuan","ex__longdan","yirong","weilingy","duoshou","ol__huxiao","ol__qirang","ol__yuhua","yuxu",
  "sheyan","juanxia","kangrui","zhenying","yanru","jilis","longyin","os_ex__xuhe","os_ex__qianxi","os__qingkou","os__zhiming"},

  wu={"ol_ex__tianxiang","ol_ex__fenji","tianyi","ol_ex__wulie","ol_ex__dimeng","ol_ex__jiang","ol_ex__zhijian","ol_ex__buyi","ol__dulie","shenxing","aocai","lixia","dingpan",
  "weiyi","xianbi","cangxin","runwei","ol__fengyan","suji","chanshuang","heji","guanwei","os_ex__shenxing","os__congji","xiaoji","ol_ex__lihuo","os__yilie","ty__songshu","ty_ex__danshou"},

  qun={"ol_ex__leiji","fuyuanx","ol_ex__shuangxiong","ol_ex__luanwu","ol_ex__zishou","anyong","os__cuijin","os__zhuidu","os__beini","os__fupan","os__qingtao","os__jiekuang","os__kujian",
  "ol__zhuiji","ol__shichou","ol__zhendu","ol__niluan","xiying","wenji","fuji","gangzhi","neifa","yuanzi","liantao","pingduan","renxia","os__gongge","os__cairu","os__xiawang","os__zhenhu"
  },
}
--修罗对抗武将
local battleToGens = {"wm_guanyu","baiqi","godzhangjiao","ty__liuye","caojinyu","tenggongzhu","guozhao","ty__sunyi","godganning","zerong","hulao2__godlvbu","zhouyi","dukui","ty__wangchang","hulao3__godlvbu"}
-- battleToGens = {"baiqi","baiqi","baiqi","baiqi","baiqi"}
--玩家测试武将
local TESTgen = "mouxusheng"
--测试AI武将（避免自由选）
local TESTgens = {"guozhao","m_ex__liaohua","zhangfen","xielingyu","zhouyi","ol__tengfanglan","dongyun","l__zhangliao","ex__simayi","ol_ex__zhangjiao","ty_ex__zhuran","l__lvbu","ty__yanghu","zhaotongzhaoguang","miniex__huangyueying","ty__yanghu","godzhaoyun","js__guanyu","lvlingqi","dukui","ty_ex__wuyi","ol_ex__sunjian","xizhicai","qinmi","godganning","ty__chenlin","ex__ganning","yuejiu","caomao","ty__lidian","ol__luyusheng","godganning","ty_ex__caozhi","zhaotongzhaoguang"}
--过滤其他卡组（只允许白名单的卡组加入牌堆）
local WHILEcards = {"standard","standard_cards","maneuvering","lang_cards","tenyear_token","mobile_derived","ol_token","overseas_token"}
--保留玩家本模式重要的标记
-- local SAVEmarks = {"curlayerphase","@slash_dmg","@trick_dmg","@pdlbox","@gold_num","@df_lingxin","@shieldnum","@slash_num"}

local norkj_getLogic = function()
  local norkj_logic = GameLogic:subclass("norkj_logic")

  function norkj_logic:initialize(room)
    GameLogic.initialize(self, room)
    -- for k,skills in pairs(qiangjiangSkills) do
    --   for _,ski in ipairs(skills) do
    --     local fkskills = Fk.skills
    --     if not fkskills[ski] then
    --       p(ski)
    --       dbg()
    --     end
    --   end
    -- end
    self.role_table = {
      { "lord" },
      { "lord", "rebel" },
      { "lord", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "loyalist", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "loyalist" },
    }
    room.KJobj = KJobj:new({
      nextBattleData = nextBattleData,
      upMarks = UpMarks,
      istest = IStest,
    })
  end

  function norkj_logic:prepareForStart()
    self.room:setTag("@curturn",curTurn)
    self.room:setTag("@battleturn",battleTurn)
    self.room.KJobj:logic_prepareForStart({
      otherbanners = {{"@[:]norkjbaner_rule","norkj-intro"},{"@totalbattle",curTurn.."/"..battleTurn},{"@seefriendcardstart",""}}
    })
  end

  function norkj_logic:prepareDrawPile()
    self.room.KJobj:logic_prepareDrawPile({
      excepts = {"lightning","crossbow"},
      whitecards = WHILEcards
    })
  end

  function norkj_logic:assignRoles()
    self.room.KJobj:logic_assignRoles({
      role_table = self.role_table
    })
  end

  function norkj_logic:chooseGenerals()
    local room = self.room
    local lord = room:getLord()
    room.current = lord

    SelGenMuty:new({
      generalNum=7,
      repcount = 4,
      istest = IStest,
      openhobbygens = true,
      genpoolname = "NOR_XLKJ",
    })
  end
  return norkj_logic
end

---------------------------------------技能--------------------------------------------
--战功
local gongjue = fk.CreateTriggerSkill{
  name = "kj_gongjue",
  frequency = Skill.Compulsory,
  anim_type = "offensive",
  events = {fk.DrawNCards,fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.DrawNCards then
      return player:getMark("@drcdnum") > 0 and player == target
    elseif event == fk.RoundStart then
      return player:getMark("@shieldadd") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DrawNCards then
      data.n = data.n + player:getMark("@drcdnum")
    elseif event == fk.RoundStart then
      local mark = player:getMark("@shieldadd")
      if player.shield < mark then
        room:changeShield(player, mark - player.shield)
      end
    end
  end,
  refresh_events = {fk.CardUseFinished,fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.CardUseFinished then
      return player == target and data.card and data.card.trueName == "slash" and player.slashtarmark and player.slashtarmark[2] > 0
    else
      return player == target and player.slashtarmark and player.slashtarmark[1] > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      player.slashtarmark[2] = player.slashtarmark[2] - 1
      if player.slashtarmark[2] <= 0 then
        room:setPlayerMark(player,"@slashtar",0)
      end
    else
      player.slashtarmark[2] = player.slashtarmark[1]
      if player:getMark("@slashtar") == 0 then
        room:setPlayerMark(player,"@slashtar",player.slashtarmark[1])
      end
    end
  end
}
local gongjue_maxhands = fk.CreateMaxCardsSkill{
  name = "#gongjue_maxhands",
  correct_func = function (self, player)
    if player:hasSkill(gongjue) and player:getMark("@handsmax") > 0 then
      return player:getMark("@handsmax")
    end
  end,
}
local gongjue_targetmod = fk.CreateTargetModSkill{
  name = "#gongjue_targetmod",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill(gongjue) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase and player:getMark("@slashadd") > 0 then
      return player:getMark("@slashadd")
    end
  end,
  extra_target_func = function(self, player, skill)
    if player:hasSkill(gongjue) and skill.trueName == "slash_skill" and player:getMark("@slashtar") > 0 then
      return player:getMark("@slashtar")
    end
  end,
}
gongjue:addRelatedSkill(gongjue_maxhands)
gongjue:addRelatedSkill(gongjue_targetmod)
Fk:addSkill(gongjue)
--飞马
local feima = fk.CreateDistanceSkill{
  name = "kj_feima",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) and from:getMark("@feima_sub") > 0 then
      return -from:getMark("feima_sub")
    end
    if to:hasSkill(self) and to:getMark("@feima_add") > 0 then
      return to:getMark("@feima_add")
    end
  end,
}
Fk:addSkill(feima)
--斩将
local handleRwdMark = function(to,from,mark)
  local room = to.room
  if string.startsWith(mark,"@") then
    local add_v = 1
    if mark == "@shieldadd" then
      local shieldnum = to:getMark("@shieldadd")
      if to.shield < shieldnum + 1 then
        room:changeShield(to, 1)
      end
    elseif mark == "@handsmax" then
      add_v = 2
    elseif mark == "@slashtar" then
      to.slashtarmark = to.slashtarmark or {0,0}
      to.slashtarmark[1] = to.slashtarmark[1] + add_v
      to.slashtarmark[2] = to.slashtarmark[1]
    end 
    room:addPlayerMark(to,mark,add_v)     
  elseif mark == "jianghun_rwd" then
    local jianghungen = from:getMark("@zhanjiang_jianghun")
    local jianghunmark = U.getPrivateMark(to, "&jianghungens")
    table.insert(jianghunmark, jianghungen)
    U.setPrivateMark(to, "&jianghungens", jianghunmark,table.map(room.players,function(pr) return pr.id end))
    if not to:hasSkill("jianghunchange") then
      room:handleAddLoseSkills(to, "jianghunchange", nil, false)
    end
    -- if not room:askForSkillInvoke(to, "askchangejianghun", nil, "#askchangejianghun:::"..Fk:translate(jianghungen)) then
    --   return
    -- end
    
  elseif mark == "addmaxhp_1" then
    to.hp = to.hp + 1
    to.maxHp = to.maxHp + 1
    room:setPlayerProperty(to, "hp", to.hp)
    room:setPlayerProperty(to, "maxHp", to.maxHp)
    to.addmaxhp = (to.addmaxhp or 0) + 1
  elseif mark == "draw_4" then
    room:drawCards(to,4,"kj_wangyu")
  end
end
local getRandWangyuRwd = function(to,from,rwdmarks)
  local room = to.room
  local getmarks = rwdmarks
  table.insert(getmarks,"addmaxhp_1")
  table.shuffle(getmarks)
  local chc = table.slice(getmarks, 1, 4)
  if to.slashtarmark and to.slashtarmark[1] >= 2 and table.contains(chc,"@slashtar") then
    table.removeOne(chc,"@slashtar")
    table.insert(chc,getmarks[#getmarks])
  end
  local selchs = room:askForChoice(to, chc, "kj_wangyu","#kj_wangyu_reward",true)
  handleRwdMark(to,from,selchs)
end
local changeJiangHuns ={
  "mobile__wenyang","mobile__caomao","mobile__duyu","js__simazhao","luotong","liyan","zhangxuan","ty__liuye","godguojia","godsunce","godganning","sunchen","zhouyi","guozhao","zhangfen",
}
local jianghunchange = fk.CreateActiveSkill{
  name = "jianghunchange",
  prompt = function()
    local jianghunmark = U.getPrivateMark(Self, "&jianghungens")
    return #jianghunmark == 1 and "#jianghunchange-alone:::"..Fk:translate(jianghunmark[1]) or "#jianghunchange-muty"
  end,
  can_use = function(self, player)
    local jianghunmark = U.getPrivateMark(player, "&jianghungens")
    return #jianghunmark ~= 0 and true or false
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_num = 0,
  on_use = function(self, room, effect)
    local to = room:getPlayerById(effect.from)
    local jianghunmark = U.getPrivateMark(to, "&jianghungens")
    -- if #jianghunmark == 0 then return end
    local changegeneral = room:askForGeneral(to, jianghunmark, 1,true)

    local loseskills = ""
    local gen = Fk.generals[to.originskin or to.general]
    local genskills = gen:getSkillNameList()
    for _,s in ipairs(genskills) do
      loseskills = loseskills.."-"..s.."|"
    end
    room:handleAddLoseSkills(to, loseskills, nil, false)
    -- end
    room:changeHero(to, changegeneral, false, false, true)

    table.removeOne(jianghunmark,changegeneral)
    U.setPrivateMark(to, "&jianghungens", jianghunmark,table.map(room.players,function(pr) return pr.id end))

    local addmaxhp = to.addmaxhp or 0
    if addmaxhp > 0 then
      to.maxHp = to.maxHp + addmaxhp
      room:setPlayerProperty(to, "maxHp", to.maxHp)
      -- to.addmaxhp = 0
    end
  end,
}
Fk:addSkill(jianghunchange)

local skinchange = fk.CreateActiveSkill{
  name = "skinchange",
  prompt = function()
    local skinmark = U.getPrivateMark(Self, "&skingens")
    return #skinmark == 1 and "#skinchange-alone:::"..Fk:translate(skinmark[1]) or "#skinchange-muty"
  end,
  can_use = function(self, player)
    local skinmark = U.getPrivateMark(player, "&skingens")
    return #skinmark ~= 0 and true or false
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_num = 0,
  on_use = function(self, room, effect)
    local to = room:getPlayerById(effect.from)
    local origingen = to.general
    local skinmark = U.getPrivateMark(to, "&skingens")
    local changeskinname = room:askForGeneral(to, skinmark, 1,true)

    room.KJobj:changeSkin(to,changeskinname)

    -- table.removeOne(skinmark,changeskinname)
    -- table.insert(skinmark,origingen)
    -- U.setPrivateMark(to, "&skingens", skinmark)
  end,
}
Fk:addSkill(skinchange)

local wangyu = fk.CreateTriggerSkill{
  name = "kj_wangyu",
  anim_type = "control",
  priority = 9,
  frequency = Skill.Compulsory,
  events = {fk.BeforeGameOverJudge,fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    if event == fk.BeforeGameOverJudge then
      return target == player and player:hasSkill(self,false,true) and data.damage and data.damage.from and not data.damage.from.dead and data.damage.from:hasSkill("kj_gongjue")
    else
      return player == target and self == data
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.BeforeGameOverJudge then
      local to = data.damage.from
      if player.wangyurwd and player.wangyurwd ~= "unknow_reward" then
        -- local _,lenth = string.find(player.wangyurwd,"@zhanjiang_rwd")
        -- local mark = string.sub(player.wangyurwd,lenth+1)
        handleRwdMark(to,player,player.wangyurwd)
      else
        getRandWangyuRwd(to,player,table.clone(UpMarks))
      end
      room:setPlayerMark(player,"@zhanjiang_rwd",0)
      room:setPlayerMark(player,"@zhanjiang_jianghun",0)
      room:handleAddLoseSkills(player,"-"..self.name,nil,false)
    else
      local randzhanjiang = table.random(wangyuRwds)    
      local zhanjiangstr = "@zhanjiang_rwd"  
      if randzhanjiang == "jianghun" then
        if not room.jianghungens then
          room.jianghungens = {}
        end
        if #room.jianghungens ~= #changeJiangHuns then
          local canrandjianghuns = {}
          for _,gen in ipairs(changeJiangHuns) do
            if not table.contains(room.jianghungens,gen) then
              table.insert(canrandjianghuns,gen)
            end
          end
          local randjianghun = table.random(canrandjianghuns)
          table.insert(room.jianghungens,randjianghun)
          player.wangyurwd = "jianghun_rwd"
          room:setPlayerMark(player,"@zhanjiang_jianghun",randjianghun)
        else
          local newrandzhanjiang = table.removeOne(table.clone(wangyuRwds),"jianghun")
          player.wangyurwd = newrandzhanjiang
          room:setPlayerMark(player,zhanjiangstr,newrandzhanjiang)
        end
      else
        player.wangyurwd = randzhanjiang
        room:setPlayerMark(player,zhanjiangstr,randzhanjiang)
      end
    end
  end,
}
Fk:addSkill(wangyu)
---------------------------------------技能--------------------------------------------
--全服4v4抗人机模式
local norkj_rule = fk.CreateTriggerSkill{
  name = "#norkj_rule",
  priority = 0.001,
  refresh_events = {fk.RoundStart,fk.BuryVictim,fk.GameStart,fk.GameOverJudge,fk.DrawInitialCards,fk.GamePrepared,fk.HpChanged,fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    if event == fk.HpChanged then
      if player == target and player.room.seeskinman then
        local ret = player.room.KJobj:HpChangedEvt(player)
        if ret then
          self.cost_data = ret
          return true
        end
      end 
      return 
    end
    if event == fk.RoundStart or event == fk.GameStart or event == fk.GamePrepared then
      return player.role == "lord"
    elseif event == fk.BuryVictim or event == fk.Deathed or event == fk.GameOverJudge then
      return player == target
    elseif event == fk.DrawInitialCards then
      return player == target and player.id < 0 and player.room:getTag("rebotdrawnum") and player.room:getTag("rebotdrawnum") > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      room.KJobj:roundStart()
    elseif event == fk.BuryVictim then
      room.KJobj:buryVictim(data.who)
    elseif event == fk.Deathed then
      room.KJobj:deaThed(data.who)
    elseif event == fk.GameOverJudge then
      room.KJobj:gameOverJudge()
    elseif event == fk.GameStart then
      room.KJobj:gameStart()
    elseif event == fk.GamePrepared then
      room.KJobj:gamePrepared()
    elseif event == fk.DrawInitialCards then
      room.KJobj:drawInitialCards(data)
    elseif event == fk.HpChanged then
      room.KJobj:changeSkin(player,self.cost_data)
    end
  end,
}
Fk:addSkill(norkj_rule)

local norkj_mode = fk.CreateGameMode{
  name = "norkj_mode",
  minPlayer = 8,
  maxPlayer = 8,
  rule = norkj_rule,
  logic = norkj_getLogic,
  whitelist = table.clone(WHILEcards),
  winner_getter = function(self, victim)
    return ""
  end,
  surrender_func = function(self, playedTime)
    local surrenderJudge = { { text = "time limitation: 10s", passed = playedTime >= 10 } }
    -- if Self.role ~= "lord" then
      table.insert(surrenderJudge, { text = "1v1: left you alive", passed = true})
    -- end
    return surrenderJudge
  end,
}

Fk:loadTranslationTable{
  ["norkj_mode"] = "全服4v4抗人机",
  ["#norkj_rule"] = "全服4v4抗人机",
  ["@[:]norkjbaner_rule"] = "全服4v4抗人机",

  ["@totalbattle"] = "挑战小杀组：",

  ["kj_gongjue"] = "战功",
  [":kj_gongjue"] = "锁定技，当你获得某些标记能够强化自身。（标记有：摸牌阶段摸牌，手牌上限，每轮开始获得护盾，额外使用杀次数，额外杀目标数）",
  ["#gongjue_maxhands"] = "战功",
  ["#gongjue_targetmod"] = "战功",

  ["jianghunchange"] = "将魂",
  ["#jianghunchange-alone"] = "是否换 %arg",
  ["#jianghunchange-muty"] = "是否从将魂列表里选1个武将变身？",
  [":jianghunchange"] = "你可以从你将魂列表里换个武将。",
  ["@[private]&jianghungens"] = "将魂",

  ["skinchange"] = "皮肤",
  ["#skinchange-alone"] = "是否换 %arg 皮肤",
  ["#skinchange-muty"] = "是否换一个皮肤？",
  [":skinchange"] = "你可以从你皮肤列表里换个皮肤。",
  ["@[private]&skingens"] = "皮肤",

  ["kj_feima"] = "飞马",
  [":kj_feima"] = "锁定技，你与其他角色距离+x，距离-y（x为获得距离+标记值，y为获得距离-标记值）",
  ["kj_wangyu"] = "斩将",
  ["#kj_wangyu_reward"] = "你可以从3选1获得标记奖励",
  ["@zhanjiang_rwd"] = "斩将:",
  ["@zhanjiang_jianghun"] = "斩将:将魂 ",
  ["unknow_reward"] = "未知奖励",
  ["addmaxhp_1"] = "体力上限+1",
  -- ["rechp_2"] = "恢复2点体力",
  ["draw_4"] = "摸4张牌",
  [":kj_wangyu"] = "锁定技，当你死亡时，杀死你的角色获得此技能标记加成（需要目标带有【战功】技能才有效）",

  ["@drcdnum"] = "摸牌+",
  [":@drcdnum"] = "摸牌阶段多摸x张牌（x为摸牌+标记）",
  ["@handsmax"] = "上限+",
  [":@handsmax"] = "你的手牌上限+x（x为上限+标记）",
  ["@shieldadd"] = "护盾+",
  [":@shieldadd"] = "每轮开始你的护甲+x（x为护盾+标记）",
  ["@slashadd"] = "杀次数+",
  [":@slashadd"] = "你回合内额外使用杀次数+x（x为杀次数+标记）",
  ["@slashtar"] = "杀目标+",
  [":@slashtar"] = "你使用杀指向目标+x（x为杀目标+标记且只有前x张杀有效,你的回合开始重置次数）",
  ["addmaxhp_1"] = "体力上限+1",
  [":addmaxhp_1"] = "体力上限+1",

  ["@feima_sub"] = "距离-",
  ["@feima_add"] = "距离+",

  ["norkj-intro"]="点击介绍",
  [":norkj-intro"]= desc_norkj_mode,

  ["#selhobby"] = "将池爱好选择",
  ["selhobby"] = "将池可根据爱好进行选择",
  ["#skinhobby"] = "皮肤（限女将）爱好选择",
  ["skinhobby"] = "某些武将降到一定体力会自动换皮肤可根据喜好是否想观看",

  ["seeskin"] = "看皮肤",
  [":seeskin"] = "某些女将降到一定体力你会看到其皮肤",
  ["noskin"] = "不看皮肤",
  [":noskin"] = "不看所有女将皮肤",

  ["allmale"] = "男将池",
  [":allmale"] = "此选将将池全部为男性",
  ["allfemale"] = "女将池",
  [":allfemale"] = "此选将将池全部为女性",
  ["randsel"] = "随机",
  [":randsel"] = "将池武将随机选择",

  ["askchangejianghun"] = "将魂",
  ["#askchangejianghun"] = "将魂换将：你可以把自身武将换成 %arg。",

  [":norkj_mode"] = desc_norkj_mode,
}

return norkj_mode
